package com.sctvcloud.bazhong.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.sctvcloud.bazhong.R;
import com.sctvcloud.bazhong.beans.FComment;
import com.sctvcloud.bazhong.ui.adapter.holder.CommentHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/26 0026.
 */

public class CommentAdapter extends BaseHolderAbsAdapter<FComment, CommentHolder> {
    public CommentAdapter(Context context, List<FComment> list) {
        super(context, list);
    }
    @Override
    public CommentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_topic_detail_comment, null);
        CommentHolder holder = new CommentHolder(context, view,data);
        holder.setInternalClick(this);
        return holder;
    }

    @Override
    public CommentAdapter setItemInternalClick(OnItemInternalClick itemInternalClick) {
        super.setItemInternalClick(itemInternalClick);
        return this;
    }

    @Override
    public int addData(FComment iListShowData) {
        if (iListShowData != null) {
            if (data == null) {
                data = new ArrayList<>();
            }
            int insert = data.size();
            data.add(iListShowData);
            notifyItemInserted(insert);
            notifyDataSetChanged();
            return insert;
        }
        return -1;
       // return super.addData(iListShowData);
    }

    @Override
    public int addData(FComment t, int pos) {
        if (t == null) {
            return -1;
        }
        if (data == null) {
            data = new ArrayList<>();
        }
        int count = data.size();
        if (pos < 0 || pos >= count) {
            pos = count;
            data.add(t);
        } else {
            data.add(pos, t);
        }
        notifyItemInserted(pos);
        notifyDataSetChanged();
        return pos;
    }
}
